package com.ysyc.driver_ee.widget;

import android.content.Context;
import android.support.annotation.StringRes;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.ysyc.driver_ee.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SureAndCancelDialog extends DialogHelp {


    @BindView(R.id.titleTv)
    TextView titleTv;
    @BindView(R.id.messageTv)
    TextView messageTv;
    @BindView(R.id.cancelTv)
    TextView cancelTv;
    @BindView(R.id.sureTv)
    TextView sureTv;

    private onDialogClickListener listener;

    public SureAndCancelDialog(Context context) {
        super(context);

        initView();
    }

    private void initView() {
        View dialogView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_sure_cancel, null);
        ButterKnife.bind(this, dialogView);

        setContentView(dialogView);

        setCancelable(false);
        setCanceledOnTouchOutside(false);
    }

    public SureAndCancelDialog setTitleText(String title) {
        titleTv.setText(title);
        return this;
    }

    public SureAndCancelDialog setTitleText(@StringRes int string) {
        titleTv.setText(getContext().getResources().getString(string));
        return this;
    }

    public SureAndCancelDialog setMessageText(String message) {
        messageTv.setText(message);
        return this;
    }

    public SureAndCancelDialog setMessageText(@StringRes int string) {
        messageTv.setText(getContext().getResources().getString(string));
        return this;
    }

    public SureAndCancelDialog setSureText(@StringRes int string) {
        sureTv.setText(getContext().getResources().getString(string));
        return this;
    }

    public SureAndCancelDialog setCancelText(@StringRes int string) {
        cancelTv.setText(getContext().getResources().getString(string));
        return this;
    }

    public SureAndCancelDialog setSureText(String string) {
        sureTv.setText(string);
        return this;
    }

    public SureAndCancelDialog setCancelText(String string) {
        cancelTv.setText(string);
        return this;
    }

    public SureAndCancelDialog setOnDialogClickListener(onDialogClickListener listener) {
        this.listener = listener;
        return this;
    }

    @OnClick(R.id.sureTv)
    public void sureTvClick() {
        if (listener != null) {
            listener.onPositiveButtonClick(this);
            dismiss();
        }
    }

    @OnClick(R.id.cancelTv)
    public void cancelTvClick() {
        if (listener != null) {
            dismiss();
        }

    }

    public interface onDialogClickListener {
        void onPositiveButtonClick(SureAndCancelDialog dialog);


    }



}
